package com.qf.zhijia.service.impl;

import com.qf.zhijia.mapper.AddressMapper;
import com.qf.zhijia.pojo.Address;
import com.qf.zhijia.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Canaan
 * @version V1.0
 * @data 2020/09/05
 **/
@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    AddressMapper addressMapper;
    @Override
    public List<Address> findAddressByUId(int uId) {
        List<Address> addresses = addressMapper.selectAddressByUid(uId);
        return addresses;
    }

    @Override
    public void AddAddress(Address address) {
        addressMapper.insertAddress(address);
    }

    @Override
    public void deleteAddressByAid(String aId) {
        addressMapper.deleteAddressByAId(aId);
    }

    @Override
    public void setAddressToDefault(String aId, int uId) {
        //将aid为0改为1，设置默认地址
        addressMapper.setAddressDeFalut(aId);
        //将aid为1的改为0，变成普通地址
        addressMapper.setAddressCommons(aId,uId);
    }

    @Override
    public void updateByAid(Address address) {
        addressMapper.updateAddressByAid(address);
    }
}
